package com.lanqiao.companymanage.lnterceptor;

import com.alibaba.fastjson.JSON;
import com.lanqiao.companymanage.utils.Constant;
import com.lanqiao.companymanage.utils.Result;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;

/**
 * @author 何小棍
 * 登录拦截器
 */
@Component
public class LoginInterceptor implements HandlerInterceptor {
    /**
     * 请求都会被拦截下来
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        HttpSession session = request.getSession();
//        Object user = session.getAttribute(Constant.USER_SESSION);
//        if (user == null){
//            response.setContentType("text/html;charset=utf-8");
//            // 如果session 中不存在user 则表示未登录
//            String jsonString = JSON.toJSONString(Result.NoLogin());
//            response.getWriter().println(jsonString);
//            return  false;
//        }
        return true;
    }
}
